/*
    BibleNotebook - A bible reader software
    Copyright (C) 2014  Williams Fernando Lopez

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
 */

/*
 * GeneralConfigPanel.java
 * Created on 9/07/2013, 08:50:20 AM
 */

package com.simplebible.ui.components;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPopupMenu;
import com.simplebible.Main;
import wl.util.TextResourcesUtil;
import com.simplebible.objects.Preferences;
import com.simplebible.ui.AboutDialog;

/**
 *
 * @author Williams Lopez
 */
public class GeneralConfigPanel extends javax.swing.JPanel {

    JPopupMenu popup = new JPopupMenu();

    private ActionListener changeIdiomaListener;
    private ActionListener enableWindowButtonListener;
    private ActionListener enableAnimacionListener;
    private ActionListener enableDisableHorizontalLayout;

    /** Creates new form GeneralConfigPanel */
    public GeneralConfigPanel() {
        initComponents();
        this.buttonGroup1.add(radioButtonEspanol);
        this.buttonGroup1.add(radioButtonIngles);
        popup.add(this);


        try {
            TextResourcesUtil.registrarComponente(this);
        } catch (Exception e) {
        }

    }

    @Override
    public void setVisible(boolean aFlag) {
        popup.setVisible(aFlag);
    }

    public void show(Component inv, int x, int y) {
        setValoresPreferencias();
        this.setVisible(true);
        popup.show(inv, x, y);
    }

    private void setValoresPreferencias() {

        radioButtonEspanol.setSelected(false);
        radioButtonIngles.setSelected(false);

        if(Preferences.getInst().getIdioma().equals(Preferences.IDIOMA_ES)){
            radioButtonEspanol.setSelected(true);
        }else if(Preferences.getInst().getIdioma().equals(Preferences.IDIOMA_EN)){
            radioButtonIngles.setSelected(true);
        }else{
            radioButtonEspanol.setSelected(true);
        }

        checkBoxAnimacion.setSelected(Preferences.getInst().isAnimation());
        checkBoxLayout.setSelected(Preferences.getInst().isHorizontalLayout());
    }

    public ActionListener getChangeIdiomaListener() {
        return changeIdiomaListener;
    }

    public void setChangeIdiomaListener(ActionListener changeIdiomaListener) {
        this.changeIdiomaListener = changeIdiomaListener;
    }

    public ActionListener getEnableWindowButtonListener() {
        return enableWindowButtonListener;
    }

    public void setEnableWindowButtonListener(ActionListener enableWindowButtonListener) {
        this.enableWindowButtonListener = enableWindowButtonListener;
    }

    public ActionListener getEnableAnimacionListener() {
        return enableAnimacionListener;
    }

    public void setEnableAnimacionListener(ActionListener enableAnimacionListener) {
        this.enableAnimacionListener = enableAnimacionListener;
    }

    public ActionListener getEnableDisableHorizontalLayout() {
        return enableDisableHorizontalLayout;
    }

    public void setEnableDisableHorizontalLayout(ActionListener enableDisableHorizontalLayout) {
        this.enableDisableHorizontalLayout = enableDisableHorizontalLayout;
    }

    

    



    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        panelIdioma = new javax.swing.JPanel();
        radioButtonEspanol = new javax.swing.JRadioButton();
        radioButtonIngles = new javax.swing.JRadioButton();
        buttonAbout = new wl.ui.ButtonLabel();
        panelInterfaz = new javax.swing.JPanel();
        checkBoxAnimacion = new javax.swing.JCheckBox();
        checkBoxLayout = new javax.swing.JCheckBox();
        panelAdministrar = new javax.swing.JPanel();
        buttonManVersion = new wl.ui.ButtonLabel();

        setBackground(new java.awt.Color(255, 255, 255));

        panelIdioma.setBackground(new java.awt.Color(255, 255, 255));
        panelIdioma.setBorder(javax.swing.BorderFactory.createTitledBorder("Idioma"));
        panelIdioma.setOpaque(false);

        radioButtonEspanol.setBackground(new java.awt.Color(255, 255, 255));
        radioButtonEspanol.setText("Español");
        radioButtonEspanol.setOpaque(false);
        radioButtonEspanol.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioButtonEspanolActionPerformed(evt);
            }
        });

        radioButtonIngles.setBackground(new java.awt.Color(255, 255, 255));
        radioButtonIngles.setText("Ingles");
        radioButtonIngles.setOpaque(false);
        radioButtonIngles.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioButtonInglesActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelIdiomaLayout = new javax.swing.GroupLayout(panelIdioma);
        panelIdioma.setLayout(panelIdiomaLayout);
        panelIdiomaLayout.setHorizontalGroup(
            panelIdiomaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelIdiomaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(radioButtonEspanol)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(radioButtonIngles)
                .addContainerGap(132, Short.MAX_VALUE))
        );
        panelIdiomaLayout.setVerticalGroup(
            panelIdiomaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelIdiomaLayout.createSequentialGroup()
                .addGroup(panelIdiomaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(radioButtonEspanol)
                    .addComponent(radioButtonIngles))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        buttonAbout.setIcon(new javax.swing.ImageIcon(getClass().getResource("/simplebible/ui/img/info_16.png"))); // NOI18N
        buttonAbout.setText("Acerca de BibleNotebook");
        buttonAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonAboutActionPerformed(evt);
            }
        });

        panelInterfaz.setBorder(javax.swing.BorderFactory.createTitledBorder("Opciones de Interfaz Gráfica"));
        panelInterfaz.setOpaque(false);

        checkBoxAnimacion.setBackground(new java.awt.Color(255, 255, 255));
        checkBoxAnimacion.setText("Activar animaciones");
        checkBoxAnimacion.setToolTipText("Activar animaciones consume más recursos (memoria y cpu)");
        checkBoxAnimacion.setOpaque(false);
        checkBoxAnimacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkBoxAnimacionActionPerformed(evt);
            }
        });

        checkBoxLayout.setText("Disposición Horizontal/Vertical");
        checkBoxLayout.setOpaque(false);
        checkBoxLayout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkBoxLayoutActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelInterfazLayout = new javax.swing.GroupLayout(panelInterfaz);
        panelInterfaz.setLayout(panelInterfazLayout);
        panelInterfazLayout.setHorizontalGroup(
            panelInterfazLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelInterfazLayout.createSequentialGroup()
                .addGroup(panelInterfazLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(checkBoxAnimacion)
                    .addComponent(checkBoxLayout))
                .addContainerGap(91, Short.MAX_VALUE))
        );
        panelInterfazLayout.setVerticalGroup(
            panelInterfazLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelInterfazLayout.createSequentialGroup()
                .addComponent(checkBoxAnimacion)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(checkBoxLayout)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelAdministrar.setBorder(javax.swing.BorderFactory.createTitledBorder("Administrar biblias/diccionarios"));
        panelAdministrar.setOpaque(false);

        buttonManVersion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/simplebible/ui/img/file_manager16.png"))); // NOI18N
        buttonManVersion.setText("Instalar/Eliminar Versiones o Diccionarios");
        buttonManVersion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonManVersionActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelAdministrarLayout = new javax.swing.GroupLayout(panelAdministrar);
        panelAdministrar.setLayout(panelAdministrarLayout);
        panelAdministrarLayout.setHorizontalGroup(
            panelAdministrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAdministrarLayout.createSequentialGroup()
                .addComponent(buttonManVersion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(44, Short.MAX_VALUE))
        );
        panelAdministrarLayout.setVerticalGroup(
            panelAdministrarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelAdministrarLayout.createSequentialGroup()
                .addComponent(buttonManVersion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelIdioma, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelInterfaz, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(panelAdministrar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(125, Short.MAX_VALUE)
                .addComponent(buttonAbout, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(panelIdioma, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelInterfaz, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(panelAdministrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(buttonAbout, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void radioButtonEspanolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioButtonEspanolActionPerformed
        if(radioButtonEspanol.isSelected()){
            if(getChangeIdiomaListener()!=null){
                ActionEvent ae = new ActionEvent(Preferences.IDIOMA_ES, 0, "selectIdioma");
                getChangeIdiomaListener().actionPerformed(ae);
            }
        }
    }//GEN-LAST:event_radioButtonEspanolActionPerformed

    private void radioButtonInglesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioButtonInglesActionPerformed
        if(radioButtonIngles.isSelected()){
            if(getChangeIdiomaListener()!=null){
                ActionEvent ae = new ActionEvent(Preferences.IDIOMA_EN, 0, "selectIdioma");
                getChangeIdiomaListener().actionPerformed(ae);
            }
        }
    }//GEN-LAST:event_radioButtonInglesActionPerformed

    private void checkBoxAnimacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBoxAnimacionActionPerformed
        if(getEnableAnimacionListener()!=null){
            ActionEvent ae = new ActionEvent(checkBoxAnimacion.isSelected(), 0, "selectAnimation");
            getEnableAnimacionListener().actionPerformed(ae);
        }
    }//GEN-LAST:event_checkBoxAnimacionActionPerformed

    private void buttonManVersionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonManVersionActionPerformed
        DialogInstallBibles dialog = new DialogInstallBibles(Main.getMainFrame(), false);
        this.setVisible(false);
        dialog.setVisible(true);
    }//GEN-LAST:event_buttonManVersionActionPerformed

    private void buttonAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonAboutActionPerformed
        AboutDialog ad= new AboutDialog(Main.getMainFrame(), true);
        this.setVisible(false);
        ad.setVisible(true);
    }//GEN-LAST:event_buttonAboutActionPerformed

    private void checkBoxLayoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkBoxLayoutActionPerformed
        if(getEnableDisableHorizontalLayout()!=null){
            ActionEvent ae = new ActionEvent(checkBoxLayout.isSelected(), 0, "selectLayout");
            getEnableDisableHorizontalLayout().actionPerformed(ae);
        }
    }//GEN-LAST:event_checkBoxLayoutActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private wl.ui.ButtonLabel buttonAbout;
    private javax.swing.ButtonGroup buttonGroup1;
    private wl.ui.ButtonLabel buttonManVersion;
    private javax.swing.JCheckBox checkBoxAnimacion;
    private javax.swing.JCheckBox checkBoxLayout;
    private javax.swing.JPanel panelAdministrar;
    private javax.swing.JPanel panelIdioma;
    private javax.swing.JPanel panelInterfaz;
    private javax.swing.JRadioButton radioButtonEspanol;
    private javax.swing.JRadioButton radioButtonIngles;
    // End of variables declaration//GEN-END:variables



}
